package com.baoyanghui.servlet.merchant;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import com.baoyanghui.common.InterfaceAccess;
import com.baoyanghui.config.Configs;

/**
 * Servlet implementation class SearchCustomer
 */
public class SearchCustomer extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SearchCustomer() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
		response.getWriter().print("请使用POST方式调用");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		JSONObject result;
		Map<String, String> params = new HashMap<String, String>();
		
		try {
			request.setCharacterEncoding("UTF-8");

			params.put("customer_id", request.getParameter("customer_id"));
			params.put("name", request.getParameter("name"));
			params.put("mobile", request.getParameter("mobile"));
			params.put("license_number", request.getParameter("license_number"));
			params.put("model", request.getParameter("model"));
			params.put("page", request.getParameter("page"));
			params.put("page_size", "5");
			params.put("merchant_id", (String)request.getSession().getAttribute(Configs.SESSION_USER_ID));
			params.put("usercode", (String)request.getSession().getAttribute(Configs.SESSION_USERCODE));
			
			result = InterfaceAccess.callInterface("/merchant/search_customer", params);
			
			response.setCharacterEncoding("UTF-8");
			response.getWriter().write(result.toString());	
			response.getWriter().flush();
		} catch (IOException e) {
		}
	}

}
